package edu.sdjzu.exam.enums;

public enum Difficulty {
    EASY("easy", "简单"),
    MEDIUM("medium", "中等"),
    HARD("hard", "困难");

    private final String code;
    private final String display;

    Difficulty(String code, String display) {
        this.code = code;
        this.display = display;
    }

    // 获取枚举值对应的数据库存储code
    public String getCode() {
        return code;
    }

    // 获取显示用文本
    public String getDisplay() {
        return display;
    }

    // 通过数据库code反查枚举
    public static Difficulty fromCode(String code) {
        for (Difficulty level : values()) {
            if (level.code.equalsIgnoreCase(code)) {
                return level;
            }
        }
        throw new IllegalArgumentException("无效的难度级别: " + code);
    }
}
